import { _decorator, Component, Label, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('mysteryPop')
export class mysteryPop extends Component {
    @property({type:Label})
     public userName: Label = null!;
     @property({type:Label})
     public userCard: Label = null!;
    start() {

    }

    public popHid(){
        let popUp1 = this.node.getChildByName("preventPop1");
        popUp1.active = false;
        let popUp2 = this.node.getChildByName("preventPop2");
        popUp2.active = true;
    }
 /**
     * 用户输入用户名结束时的回调函数
     * 当用户完成输入用户名后，该函数将被调用
     * 目前该函数为空，您可以在此处添加处理逻辑，例如验证用户名是否符合要求
     */
    private onUserNameEnded(){

    }
/**
     * 用户输入身份证号结束时的回调函数、这个你需要的花自己加
     */
    private onUserCardEnded(){

    }

     isMinor(idCard: string): boolean {
        // 检查身份证号码长度是否正确
        if (idCard.length !== 18) {
            throw new Error("身份证号码长度不正确，应为18位");
        }
    
        // 提取出生日期部分
        const birthYear = parseInt(idCard.substring(6, 10), 10);
        const birthMonth = parseInt(idCard.substring(10, 12), 10);
        const birthDay = parseInt(idCard.substring(12, 14), 10);
    
        // 获取当前日期
        const today = new Date();
        const currentYear = today.getFullYear();
        const currentMonth = today.getMonth() + 1; // getMonth() 返回0-11
        const currentDay = today.getDate();
    
        // 计算年龄
        let age = currentYear - birthYear;
    
        // 如果当前日期还未过生日，则年龄减一
        if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
            age--;
        }
    
        // 判断是否未成年
        return age < 18;
    }
    private onSubmitClick(){
        console.log(this.userName.string);
        if(this.userName.string){
            console.log("用户名不为空");
        }
        if(this.userCard.string){
            console.log("身份证不为空");
        }

        if( this.isMinor(this.userCard.string)){
            console.log("未成年");
            let popUp3 = this.node.getChildByName("preventPop3");
            popUp3.active = true;
        }
       

    }

    update(deltaTime: number) {
        
    }
}


